package com.gc.monitor.gctask.impl;

import com.gc.gpsoo.GpsooSDK;
import com.gc.gpsoo.beans.GpsooCarData;
import com.gc.gpsoo.beans.GpsooDevData;
import com.gc.gpsoo.exception.GpsooSDKException;
import com.gc.monitor.gcexception.GCMonitorException;
import com.gc.monitor.gctask.GpsooMonitor;
import com.gc.monitor.gctask.GpsooMonitorResult;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

/**
 * 抓取Gpsoo数据任务实现类
 * Created by 瑱彬 on 2015/4/15.
 */

@Component(value = "gpsooLoadMonitor")
@Scope("singleton")
public class GpsooLoadMonitorImpl implements GpsooMonitor {
    GpsooMonitorResult gpsooMonitorResult;
    List<GpsooCarData> monitorResults;
    List<GpsooDevData> devinfoResults;

    @Override
    public void run() throws GCMonitorException {
        initGpsooMonitorResult();
        try {
            GpsooSDK gpsooSDK = GpsooSDK.getInstance();
            monitorResults = gpsooSDK.loadMonitor();
            devinfoResults = gpsooSDK.loadDevinfo();
            gpsooMonitorResult.setMonitorResults(monitorResults);
            gpsooMonitorResult.setDevinfoResults(devinfoResults);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (GpsooSDKException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取gpsooMonitorResult 缓存类的单例
     */
    private void initGpsooMonitorResult() {
        gpsooMonitorResult = GpsooMonitorResult.getInstance();
    }
}
